package com.oa.ylms.apps.actions.assess;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.oa.ylms.apps.actions.BasicAction;
import com.oa.ylms.apps.business.assess.IAssessCheckService;
import com.oa.ylms.apps.constants.assess.IAssessInfoStates;
import com.oa.ylms.apps.entity.archives.StaffInfoValue;
import com.oa.ylms.apps.entity.assess.AssessCheckValue;
import com.oa.ylms.apps.entity.assess.AssessInfoValue;

@SuppressWarnings("serial")
public class AssessCheckAction extends BasicAction {
	
	private IAssessCheckService assessCheckService;
	private List<AssessInfoValue> assessInfoList;
	private List<AssessCheckValue> assessCheckList;
	private String comments;
	private Integer status;
	private Integer assessId;
	private String assessName;
	private String modelName;
	private Integer yearNo=IAssessInfoStates.UNDEFINED;
	private Integer monthNo=IAssessInfoStates.UNDEFINED;
	private Map<String,Object> assessCheckListMap;
	
	
	public String query() {
		try {
			staffInfo = (StaffInfoValue) session.get("login_staffInfo");
			totalpage = assessCheckService.countTpagesByCheckList(staffInfo, yearNo, monthNo, modelName, assessName, rows);
			count = assessCheckService.getTotalNumber();
			if (count % rows == 0 && totalpage + 1 == currpage) {
				currpage = currpage - 1;
				totalpage = currpage;
			}
			assessInfoList=assessCheckService.queryCheckList(staffInfo, yearNo, monthNo, modelName, assessName, rows, currpage);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "show";
	}

	public String check() {
		try {
			staffInfo = (StaffInfoValue) session.get("login_staffInfo");
			if (status == 1) {
				assessCheckService.checkPassed(staffInfo, assessId, comments);
			}
			if (status == 0) {
				assessCheckService.checkFailed(staffInfo, assessId, comments);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "check";
	}
	
	public String queryDetail(){
		try {
			assessCheckList = assessCheckService.queryAssessCheckByAssessId(assessId);		                                         
		} catch (Exception e) {
			e.printStackTrace();
		}
		Gson gson = new Gson();
		assessCheckListMap.put("assessCheckList", assessCheckList);
		String str = gson.toJson(assessCheckListMap);
		try {
			response.setContentType("text/html; charset=UTF-8");
			response.setHeader("Cache-Control", "no-cache");
			response.getWriter().println(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public IAssessCheckService getAssessCheckService() {
		return assessCheckService;
	}

	public void setAssessCheckService(IAssessCheckService assessCheckService) {
		this.assessCheckService = assessCheckService;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getAssessId() {
		return assessId;
	}

	public void setAssessId(Integer assessId) {
		this.assessId = assessId;
	}

	public List<AssessInfoValue> getAssessInfoList() {
		return assessInfoList;
	}

	public void setAssessInfoList(List<AssessInfoValue> assessInfoList) {
		this.assessInfoList = assessInfoList;
	}

	public String getAssessName() {
		return assessName;
	}

	public void setAssessName(String assessName) {
		this.assessName = assessName;
	}

	public String getModelName() {
		return modelName;
	}

	public void setModelName(String modelName) {
		this.modelName = modelName;
	}

	public Integer getYearNo() {
		return yearNo;
	}

	public void setYearNo(Integer yearNo) {
		this.yearNo = yearNo;
	}

	public Integer getMonthNo() {
		return monthNo;
	}

	public void setMonthNo(Integer monthNo) {
		this.monthNo = monthNo;
	}

	public List<AssessCheckValue> getAssessCheckList() {
		return assessCheckList;
	}

	public void setAssessCheckList(List<AssessCheckValue> assessCheckList) {
		this.assessCheckList = assessCheckList;
	}

	public Map<String, Object> getAssessCheckListMap() {
		return assessCheckListMap;
	}

	public void setAssessCheckListMap(Map<String, Object> assessCheckListMap) {
		this.assessCheckListMap = assessCheckListMap;
	}

}
